 /*
  * Copyright (c) 2021, 2023, yishun.cn All rights reserved.
  *
  */

 import cn.shun.mapper.DbMapper;
 import com.alibaba.druid.pool.DruidDataSource;
 import com.mysql.jdbc.Driver;
 import org.apache.ibatis.mapping.Environment;
 import org.apache.ibatis.session.Configuration;
 import org.apache.ibatis.session.SqlSession;
 import org.apache.ibatis.session.SqlSessionFactory;
 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
 import org.apache.ibatis.transaction.TransactionFactory;
 import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;

 /**
  * <p>Project: MyBatis2023 - MybatisDemo
  * <p>Powered by yishun On 2023-01-18 22:35:06
  *
  * @author yishun [2465734101@qq.com]
  * @version 1.0
  * @since 17
  */
 public class MybatisDemo {
     SqlSessionFactory sf;
     SqlSession ss;
     DbMapper dm;
     @BeforeEach
     void init(){
         DruidDataSource ds=new DruidDataSource();
         ds.setUrl("jdbc:mysql://localhost:3306/dbtest");
         ds.setUsername("root");
         ds.setPassword("123456");
         //事务
         TransactionFactory tx=new JdbcTransactionFactory();
         //开发环境对象
         Environment env=new Environment("development",tx,ds);
         //建立配置文件
         Configuration cfg=new Configuration(env);
         //增加DbMapper.java 会自动添加同名的DbMapper.xml
         //cfg.addMapper(DbMapper.class);
         cfg.addMappers("cn.shun.mapper");
         //建立SqlSessionFactory sf
         sf=new SqlSessionFactoryBuilder().build(cfg);
         ss=sf.openSession();
         dm=ss.getMapper(DbMapper.class);
     }
     @Test
     void t1(){
         System.out.println(dm.version());
     }
     @Test
     void t2(){
         System.out.println(dm.dbs());
     }
 }
